//
//  HZZFHttpRequest.h
//  HZZFNetworking
//
//  Created by 早范 on 2025/7/7.
//  
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, HZZFHttpRequestSerializerType) {
    HZZFHttpRequestSerializerTypeHTTP = 0,
    HZZFHttpRequestSerializerTypeJSON,
};

typedef NS_ENUM(NSInteger, HZZFHttpResponseSerializerType) {
    // nsdata serializer
    HZZFHttpResponseSerializerTypeHTTP = 0,
    // json serializer
    HZZFHttpResponseSerializerTypeJSON,
    // xml serializer
    HZZFHttpResponseSerializerTypeXMLParser,
};

@class HZZFHttpRequest;
@protocol HZZFHttpRequestDelegate <NSObject>

- (void)HZZF_httpRequestSuccess:(HZZFHttpRequest *)request;
- (void)HZZF_httpRequestFail:(HZZFHttpRequest *)request;

@end

typedef void(^HZZFHttpRequestCompletionBlock)(HZZFHttpRequest *request);

@interface HZZFHttpRequest : NSObject

#pragma mark - Getter

@property (nonatomic, strong, readonly) NSURLSessionTask *requestTask;
@property (nonatomic, strong, readonly) NSHTTPURLResponse *response;
@property (nonatomic, strong, readonly) id responseObject;
@property (nonatomic, strong, readonly, nullable) NSError *error;

@property (nonatomic, readonly, getter=isCancelled) BOOL cancelled;
@property (nonatomic, readonly, getter=isExecuting) BOOL execution;

#pragma mark - Construction Setter

@property (nonatomic, copy) NSString *baseUrl;
@property (nonatomic, copy) NSString *requestUrl;
@property (nonatomic, copy) NSString *HTTPMethod;
/// default is 10 seconds
@property (nonatomic, assign) NSTimeInterval timeoutInterval;
/// default is 'HZZFHttpRequestSerializerTypeHTTP'
@property (nonatomic, assign) HZZFHttpRequestSerializerType requestSerializerType;
/// default is 'HZZFHttpRequestSerializerTypeJSON'
@property (nonatomic, assign) HZZFHttpResponseSerializerType responseSerializerType;
@property (nonatomic, strong, nullable) id requestArguments;
@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *HTTPHeaderFields;

#pragma mark - Callback setter

@property (nonatomic, copy, nullable) HZZFHttpRequestCompletionBlock successBlcok;
@property (nonatomic, copy, nullable) HZZFHttpRequestCompletionBlock failureBlock;

@property (nonatomic, weak, nullable) id<HZZFHttpRequestDelegate> delegate;

#pragma mark - Action

- (void)send;

- (void)cancel;

@end

NS_ASSUME_NONNULL_END
